﻿using GdNet.Core.Domain;
using GdNet.Core.Domain.Metadata;
using NHibernate.Mapping.ByCode;

namespace GdNet.Integrations.NHibernate.Mapping
{
    public abstract class AbstractEntityWithModificationMapping<TObject, TId> : AbstractEntityMapping<TObject, TId>
        where TObject : AbstractEntityWithModification<TId>
    {
        public AbstractEntityWithModificationMapping()
            : this(Generators.Native)
        {
        }

        public AbstractEntityWithModificationMapping(IGeneratorDef generator)
            : base(generator)
        {
            base.Property(e => e.CreatedAt, m =>
            {
                m.Column(EntityWithModificationMeta.CreatedAt);
                m.Access(Accessor.Field);
                m.NotNullable(true);
            });
            base.Property(e => e.CreatedBy, m =>
            {
                m.Column(EntityWithModificationMeta.CreatedBy);
                m.Access(Accessor.Field);
                m.NotNullable(true);
            });

            base.Property(e => e.LastModifiedAt, m =>
            {
                m.Column(EntityWithModificationMeta.LastModifiedAt);
                m.Access(Accessor.Field);
            });
            base.Property(e => e.LastModifiedBy, m =>
            {
                m.Column(EntityWithModificationMeta.LastModifiedBy);
                m.Access(Accessor.Field);
            });
        }
    }
}
